﻿Public Class frmAsignarMuestras


    Dim eMuestra As New BLcongelador
    Private tamCuadro As Integer = 20
    Private colorInactivas As System.Drawing.Color = System.Drawing.Color.FromArgb(CType(CType(189, Byte), Integer), CType(CType(189, Byte), Integer), CType(CType(189, Byte), Integer))
    Private colorVacias As System.Drawing.Color = System.Drawing.Color.FromArgb(CType(CType(74, Byte), Integer), CType(CType(67, Byte), Integer), CType(CType(222, Byte), Integer))
    Private colorOcupadas As System.Drawing.Color = System.Drawing.Color.FromArgb(CType(CType(254, Byte), Integer), CType(CType(118, Byte), Integer), CType(CType(99, Byte), Integer))

    Private Sub frmAsignarMuestras_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim cont = 0
        Dim cont1 = 0
        Dim cont2 = 0
        Dim lCaja As System.Linq.IQueryable(Of criobox)
        Dim lColums As System.Linq.IQueryable(Of columna)
        Dim lPisos As System.Linq.IQueryable(Of piso)
        Dim lCongeladores As System.Linq.IQueryable(Of congelador)

        lCongeladores = eMuestra.BuscarCongeladores()
        Dim n = Me.tvBtt.Nodes.Add("BTT")
        For Each congelador In lCongeladores

            Me.tvBtt.Nodes(0).Nodes.Add("Congelador" + cont.ToString)
            lPisos = eMuestra.BuscarPisos(congelador.id_congelador)

            For Each piso In lPisos
                Me.tvBtt.Nodes(0).Nodes(cont).Nodes.Add("Piso" + cont1.ToString)

                lColums = eMuestra.BuscarColumnas(congelador.id_congelador, piso.id_piso)

                For Each columna In lColums

                    Me.tvBtt.Nodes(0).Nodes(cont).Nodes(cont1).Nodes.Add("Columna" + cont2.ToString)

                    lCaja = eMuestra.BuscarCajas(congelador.id_congelador, piso.id_piso, columna.id_columna)

                    For Each criobox In lCaja

                        Me.tvBtt.Nodes(0).Nodes(cont).Nodes(cont1).Nodes(cont2).Nodes.Add("Caja" + criobox.id_box.ToString)
                    Next

                    cont2 = cont2 + 1
                Next

                cont1 = cont1 + 1

            Next

            cont = cont + 1


        Next


    End Sub


    Private Sub tvBtt_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvBtt.NodeMouseDoubleClick

        Dim sCaja As String
        Dim iCaja As String
        Dim nFil As Integer
        Dim nCol As Integer
        Dim lPos As System.Linq.IQueryable(Of posicion)

        sCaja = e.Node.Text.Substring(0, 4)
        If (sCaja = "Caja") Then

            Me.lblDetalle.Text = "Detalle" + " " + e.Node.Text
            iCaja = e.Node.Text.Substring(4)
            lPos = eMuestra.BuscarPosiciones(iCaja, nFil, nCol)
            dibujarDetalle(lPos, nFil, nCol)
            MsgBox(e.Node.ToString)

        End If
        
    End Sub

    Private Sub dibujarDetalle(ByVal lPos As System.Linq.IQueryable(Of posicion), ByVal nFil As Integer, ByVal nCol As Integer)

        Dim tamCuadro As Integer = 30
        Dim cont As Integer = 0


        For i As Integer = 0 To nFil - 1

            For j As Integer = 0 To nCol - 1
                Dim asiento As New Button


                asiento.Size = New Drawing.Size(tamCuadro, tamCuadro)
                asiento.Location = New Drawing.Point((j + 0.5) * tamCuadro, (i + 0.5) * tamCuadro)
                asiento.FlatStyle = FlatStyle.Standard

                If (lPos.AsEnumerable(cont).estado) Then

                    asiento.BackColor = colorVacias
                Else
                    asiento.BackColor = colorInactivas
                    asiento.Enabled = False
                End If

                Me.pnlDetalle.Controls.Add(asiento)
                cont = cont + 1


            Next

        Next


    End Sub
End Class
